
import 'package:flutter/material.dart';

class CostStatPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _CostStatState();
}

class _CostStatState extends State<CostStatPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(),
      /* body: Container(
        color: Color(u_f5f5f5),
        padding: EdgeInsets.only(left: 30, top: 10, right: 10, bottom: 10),
        child: Column(
          children: [
            Stack(
              children: [
                Row(
                  children: [
                    Text('时间', style: TextStyle(fontSize: 12)),
                    SizedBox(width: 10),
                    _dateWidget('start'),
                    Container(
                      margin: EdgeInsets.only(left: 10, right: 10),
                      child: Text('—'),
                    ),
                    _dateWidget('end'),
                    _searchBtn(),
                  ],
                ),
                Align(
                  alignment: Alignment.centerRight,
                  child: Container(
                    width: 270,
                    height: 40,
                    child: TabBar(
                      tabs: [
                        Tab(text: list[0]),
                        Tab(text: list[1]),
                        Tab(text: list[2]),
                      ],
                      labelColor: Colors.green,
                      indicatorPadding: EdgeInsets.all(0),
                      indicatorSize: TabBarIndicatorSize.label,
                      unselectedLabelColor: Color(u_2787de),
                      labelPadding: EdgeInsets.symmetric(horizontal: 10),
                      controller: _tabController,
                    ),
                  ),
                ),
              ],
            ),
            SizedBox(height: 20),
            Expanded(
              child: Row(
                children: [
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.all(20),
                      color: Colors.white,
                      child: Column(
                        children: [
                          Align(
                            child: Text(
                              '费用统计',
                              style: TextStyle(
                                color: Color(u_333333),
                                fontSize: 12,
                                fontWeight: FontWeight.w600,
                              ),
                            ),
                            alignment: Alignment.centerLeft,
                          ),
                          Expanded(child: _buildPieChart()),
                        ],
                      ),
                    ),
                  ),
                  SizedBox(width: 20),
                  Expanded(
                    flex: 2,
                    child: Container(
                      color: Colors.white,
                      child: Column(
                        children: [
                          _buildListViewHeader(),
                          Expanded(child: _buildListView()),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),*/
    );
  }
/*
  PieChartUtil _pieChartUtil;
  TabController _tabController;
  List<int> mList;

  ///存放状态和索引List
  List<DrugModel> expandStateList;

  _CostStatState() {
    mList = List();
    expandStateList = List();
    for (int i = 0; i < 22; i++) {
      mList.add(i);

      ///第一个是索引，第二个是否打开
      expandStateList.add(DrugModel(index: i, isOpen: false));
    }
*/
  // }

  //判断用户点击是否打开
 /* _setCurrentIndex(int index, bool isExpand) {
    setState(() {
      //循环判断用户点击和索引是否一致，并操作状态
      expandStateList.forEach((item) {
        if (item.index == index) {
          item.isOpen = !isExpand;
        }
      });
    });
  }*/

  // @override
  // void initState() {
  /*  _pieChartUtil = PieChartUtil();
    _testPieData();
    _tabController = TabController(
      vsync: ScrollableState(),
      length: list.length,
    );
    super.initState();*/
/*  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }*/


  ///时间选择栏
/*  Widget _dateWidget(String dateFlag) {
    return InkWell(
      child: Container(
        height: height(40),
        width: width(250),
        decoration: inputBorderBg(),
        padding: EdgeInsets.only(left: 10, right: 5),
        child: Row(
          children: [
            Expanded(
              flex: 1,
              child: Container(
                alignment: Alignment.center,
                width: 10,
                child: Row(
                  children: [
                    Expanded(
                      child: Text(
                        '2020',
                        style: TextStyle(fontSize: 12, color: Colors.black),
                        maxLines: 1,
                      ),
                    ),
                    Text(
                      '年',
                      style: TextStyle(fontSize: 10, color: Color(u_2787de)),
                    ),
                  ],
                ),
              ),
            ),
            Expanded(
              flex: 1,
              child: Container(
                width: 10,
                child: Row(
                  children: [
                    Expanded(
                      child: Text(
                        'start' == dateFlag ? '1' : '12',
                        style: TextStyle(fontSize: 12, color: Colors.black),
                      ),
                    ),
                    Text(
                      '月',
                      style: TextStyle(
                        fontSize: 10,
                        color: Color(u_2787de),
                      ),
                    ),
                    SizedBox(width: 5),
                  ],
                ),
              ),
            ),
            Image.asset(
              'assets/images/2.0x/icon_date_spinner.png',
              width: width(8),
              height: height(20),
            ),
          ],
        ),
      ),
      onTap: () {
        ToastUtil.showBasicToast('时间选择');
      },
    );
  }

  ///搜索按钮
  Widget _searchBtn() {
    return Container(
      color: Color(u_2787de),
      margin: EdgeInsets.only(left: 10),
      width: 50,
      height: 25,
      child: OutlineButton(
        padding: EdgeInsets.all(0),
        child: Text(
          '搜索',
          style: TextStyle(
              color: Colors.white, fontSize: isLargeScreen ? 12.0 : 10.0),
        ),
        onPressed: () {},
      ),
    );
  }

  ///PieChart
  Widget _buildPieChart() {
    return PieChart(_pieChartUtil.controller);
  }*/

  List<String> list = [
    '药品费',
    '诊疗费',
    '服务设施费',
  ];

/*  void _testPieData() async {
    var random = Random(1);
    List<PieEntry> entries = List();
    for (int i = 0; i < 3; i++) {
      entries.add(
        PieEntry(
          value: ((random.nextDouble() * 200.0) + 100 / 5),
          label: list[i % list.length],
        ),
      );
    }
    setState(() {
      _pieChartUtil.showPieChart(entries);
    });
  }*/

  ///右边ListView表头
/*  Widget _buildListViewHeader() {
    return Container(
      color: Color(u_bbd4ee),
      height: 30,
      child: Flex(
        direction: Axis.horizontal,
        children: <Widget>[
          dividerVertical(),
          Expanded(
            flex: 1,
            child: Text(
              '序号',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Container(width: 30),
          dividerVertical(),
          Expanded(
            flex: 2,
            child: Text(
              '药品名称',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Expanded(
            flex: 2,
            child: Text(
              '数量',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Expanded(
            flex: 2,
            child: Text(
              '金额（元）',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Expanded(
            flex: 10,
            child: Container(),
          ),
          dividerVertical(),
        ],
      ),
    );
  }

  Widget _buildListView() {
    return ListView.separated(
      padding: EdgeInsets.only(top: 0),
      itemBuilder: (context, index) => _buildListViewItem(index),
      separatorBuilder: (context, index) => dividerH(),
      itemCount: expandStateList.length,
    );
  }

  void _onTap(int index) {
    setState(() {
      DrugModel item = expandStateList[index];
      item.isOpen = !item.isOpen;
    });
  }

  Widget _buildListViewItem(int index) {
    if (expandStateList[index].isOpen) {
      DrugModel item = expandStateList[index];
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          _buildOutListItem(index),
          ListView.separated(
            padding: EdgeInsets.only(top: 0),
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              return Container(
                color: Colors.blue,
                child: ListTile(
                  title: Text('我是内层数据$index'),
                  onTap: () => _onTap(index),
                ),
              );
            },
            separatorBuilder: (context, index) => _buildOutListItem(index),
            itemCount: list.length,
          ),
        ],
      );
    } else {
      return _buildOutListItem(index);
      *//* return ListTile(
        title: Text('我是外层数据$index'),
        onTap: () => _onTap(index),
      );*//*
    }
  }

  ///外层的ListView的item
  Widget _buildOutListItem(int index) {
    return Container(
      color: (index % 2 == 0) ? Colors.white : Color(u_ffeff7fb),
      height: 30,
      child: Flex(
        direction: Axis.horizontal,
        children: <Widget>[
          dividerVertical(),
          Expanded(
            flex: 1,
            child: Text(
              '${index + 1}',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Container(
            width: 30,
            child: Center(
              child: ExpandIcon(
                onPressed: (isExpand) => _onTap(index),
                size: 20,
              ),
            ),
          ),
          dividerVertical(),
          Expanded(
            flex: 2,
            child: Text(
              '胸腺肽',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Expanded(
            flex: 2,
            child: Text(
              '15',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Expanded(
            flex: 2,
            child: Text(
              '2000',
              style: TextStyle(fontSize: isLargeScreen ? 12 : 10),
              textAlign: TextAlign.center,
            ),
          ),
          dividerVertical(),
          Expanded(
            flex: 10,
            child: Container(),
          ),
          dividerVertical(),
        ],
      ),
    );
  }

  Widget _buildInnerListItem(int index) {
    return Container(
      color: Colors.deepPurpleAccent,
    );
  }

  ///内层的ListView的item
  Widget _buildListView2() {
    return ListView.separated(
        padding: EdgeInsets.only(top: 0),
        separatorBuilder: (context, index) => _buildOutListItem(index),
        itemBuilder: (context, index) => _buildInnerListItem(index),
        itemCount: expandStateList.length);
  }*/
}
